#pragma once

#include "stdafx.h"

#include "scene/drawable.h"

namespace natrium {
	namespace scene {
		class Mesh: 
			public Drawable 
		{
		public:
			Mesh(const std::string& filename, bool reCenterMesh = false, bool loadTexCoords = false, bool generateTangents = false);

			virtual void render() const override;

			void loadObj(const std::string& filename); //[NOTE] -- while this format is simple to read, it's also somewhat slow due to the required parsing...

		private:
			std::vector<glm::vec3> generateNormals(
				const std::vector<glm::vec3>& vertices, 
				const std::vector<unsigned int>& indices
			) const;

			std::vector<glm::vec4> generateTangents(
				const std::vector<glm::vec3>& vertices, 
				const std::vector<glm::vec3>& normals, 
				const std::vector<glm::vec2>& texCoords,
				const std::vector<unsigned int>& indices
			) const;

			void center(std::vector<glm::vec3>& vertices) const;

			void createVBO(
				const std::vector<glm::vec3>& vertices, 
				const std::vector<glm::vec3>& normals, 
				const std::vector<glm::vec2>& texCoords,
				const std::vector<unsigned int>& indices,
				const std::vector<glm::vec4>& tangents
			);

			bool mReCenterMesh;
			bool mLoadTexCoords;
			bool mGenerateTangents;

			size_t mNumElements;
			GLuint mHandle;
		};
	}
}